package sorting;

public class SelectionSort {

	static int[] array = new int[] { 5, 9, 4, 0, 14, 6, 14, 99, 3, 44, 17 };

	public static void main(String[] args) {

		sort(array);

		printArray(array);

	}

	private static void sort(int[] array) {
		
		for(int i =0; i< array.length - 1; i++) {
			int lowest = array[i];
			int index = i;
			for (int j=i + 1; j < array.length; j++) {
				if (lowest > array[j]) {
					lowest = array[j];
					index = j;
				}
			}
			
			if (index != i) {
				swap(array, index, i);
			}
		}
	}
	
	private static void swap(int[] array, int i, int j) {
		int tmp = array[i];
		array[i] = array[j];
		array[j] = tmp;

	}

	private static void printArray(int[] array2) {
		for (int a : array) {
			System.out.print(a + " ");
		}
	}
}
